package com.bdqn.ch03.pojo;

import com.bdqn.ch03.SL.IntermediaryInvocationHandler;

import java.lang.reflect.Proxy;

/**
 * IntermediaryJdkProxyFactory
 * 示例8 定义代理工厂 使用Proxy类基于前文定义的代理规则为指定接口动态生成代理对象
 * @aurhor Administrator  whs
 * @since 2024/7/1
 */
public class IntermediaryJdkProxyFactory {

    public static <T> T create(Object target){
        IntermediaryInvocationHandler handler = new IntermediaryInvocationHandler();
        handler.setTarget(target);
        return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), handler);
    }

}
